package com.yilin.medical.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.yilin.medical.R;
import com.yilin.medical.adapter.GridAdapter;

/**
 * 课程首页
 * 
 * @author lijianqun
 * 
 */
public class KeChengHomeActivity extends BaseActivity implements
		OnItemClickListener {
	private GridView mGridViewHome;
	private Context context;
	int[] homeItemIds = { R.drawable.kecheng_home_zhongliu,
			R.drawable.kecheng_home_xinxueguan, R.drawable.kecheng_home_yanke,
			R.drawable.kecheng_home_xiaohua, R.drawable.kecheng_home_neifenmi,
			R.drawable.kecheng_home_more };

	private String type;
	public static final String DEPARTMENT_KEY = "department";
	public static final String DEPARTMENT_TYPE_TUMOR = "tumor";
	public static final String DEPARTMENT_TYPE_CARDIOVASCULAR = "cardiovasclar";
	public static final String DEPARTMENT_TYPE_OPHTHALMOLOGY = "hthalmology";
	public static final String DEPARTMENT_TYPE_DIGESTION = "digestion";
	public static final String DEPARTMENT_TYPE_ENDOCRINE = "endocrine";
	public static final String DEPARTMENT_TYPE_MORE = "more";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentViewWithTitle(R.layout.activity_home_kecheng);
		context = this;
		type = getIntent().getStringExtra(HomeActivity.TYPE_KEY);
		initView();
		registener();
	}

	private void initView() {
		mGridViewHome = (GridView) findViewById(R.id.gv_home);
		
		if (type.equalsIgnoreCase(HomeActivity.TYPE_COURSE)) {
			mTitle.getTitle().setText("课程");
		} else if (type.equalsIgnoreCase(HomeActivity.TYPE_MEETING)) {
			mTitle.getTitle().setText("会议");
			homeItemIds[0] = R.drawable.huiyi_home_zhongliu;
			homeItemIds[1] = R.drawable.huiyi_home_xinxueguan;
			homeItemIds[2] = R.drawable.huiyi_home_yanke;
			homeItemIds[3] = R.drawable.huiyi_home_xiaohua;
			homeItemIds[4] = R.drawable.huiyi_home_neifenmi;
			homeItemIds[5] = R.drawable.huiyi_home_more;

		} else if (type.equalsIgnoreCase(HomeActivity.TYPE_GUIDE)) {
			mTitle.getTitle().setText("指南");
		}
		mGridViewHome.setAdapter(new GridAdapter(context, homeItemIds));
	}

	private void registener() {
		mGridViewHome.setOnItemClickListener(this);
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);
		switch (v.getId()) {
		}
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {

		Intent intent = new Intent(context, KeChengActivity.class);
		intent.putExtra(HomeActivity.TYPE_KEY, type);
		switch (position) {
		case 0: // 肿瘤
			intent.putExtra(DEPARTMENT_KEY, DEPARTMENT_TYPE_TUMOR);
			break;
		case 1:// 心血管
			intent.putExtra(DEPARTMENT_KEY, DEPARTMENT_TYPE_CARDIOVASCULAR);
			break;
		case 2: // 眼科
			intent.putExtra(DEPARTMENT_KEY, DEPARTMENT_TYPE_OPHTHALMOLOGY);
			break;
		case 3:// 消化
			intent.putExtra(DEPARTMENT_KEY, DEPARTMENT_TYPE_DIGESTION);
			break;
		case 4:// 内分泌
			intent.putExtra(DEPARTMENT_KEY, DEPARTMENT_TYPE_ENDOCRINE);
			break;
		case 5:// 更多
			intent.putExtra(DEPARTMENT_KEY, DEPARTMENT_TYPE_MORE);
			break;
		}
		startActivity(intent);
	}
}
